<?php
require_once "models/usersModel.php";

class user_controller {
    public $model;
    public $action="lists";

    public  function __construct(){
		//parent::__construct();
        $this->model = new usersModel();
        if(isset($_GET['action']))$this->action=$_GET['action'];
        $this->{$this->action}();

    }
    // Method get Users
    public  function lists(){
        $listUsers = $this->model->getListUsers();
        include'views/users/listUsers.php';
    }
    //Method get user along ID
    public  function view(){
        $user = $this->model->getUser($_GET['id']);
    }
    //Method add User into database
    public  function add(){
        if(isset($_POST['btn_submit'])){

            $f_name = $_POST['f_name'];
            $l_name = $_POST['l_name'];
            $email = $_POST['email'];
            $password = md5($_POST['password']);
            $priority = $_POST['priority'];
            date_default_timezone_set('Asia/Jakarta');
            $daterg = date("Y-m-d : h-i-s ");
            $duty = $_POST['duty'];
            $this->model->addUser($f_name,$l_name, $email, $password, $priority,$duty, $daterg);
            $messager="true";
            $listUsers = $this->model->getListUsers();
            include'views/users/listUsers.php';
        }
        else{
            include'views/users/addUser.php';
        }
    }
    //Method delete
    public  function delete(){
        $id = $_GET['id'];
        $this->model->deleteUser($id);
        $mes_del = "true"; // Messager sent to page list user
        $listUsers = $this->model->getListUsers();
        include'views/users/listUsers.php';
    }


}